package cn.com.lyj6851.user.controller;

import java.util.Date;
import java.util.UUID;

import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.com.lyj6851.common.util.BeanValidator;
import cn.com.lyj6851.user.entity.Role;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 〈功能简述〉<br>
 * 〈角色〉
 *
 */
@RestController
@Api(tags = "角色Controller")
public class RoleController {

	@PostMapping("role")
    @ApiOperation("新增角色")
    public BodyBuilder add(Role role) {
		BeanValidator.check(role);
        role.setId(UUID.randomUUID().toString());
        role.setCreateTime(new Date());
        role.insert();
        return ResponseEntity.ok();
    }
	
	@DeleteMapping("role")
    @ApiOperation("删除角色")
    public BodyBuilder delete(Role role) {
        role.deleteById();
        return ResponseEntity.ok();
    }
	
	@PutMapping("role")
    @ApiOperation("修改角色")
    public BodyBuilder update(Role role){
		BeanValidator.check(role);
        role.updateById();
        return ResponseEntity.ok();
    }
}
